home *** CD-ROM | disk | FTP | other *** search
- Path: vixen.cso.uiuc.edu!usenet
- From: n-dade@uiuc.edu
- Newsgroups: comp.lang.c++
- Subject: Re: Pointer to interrupt method in BC 4.52
- Date: 15 Mar 1996 00:49:23 GMT
- Organization: University of Illinois at Urbana
- Message-ID: <4iaeqj$nli@vixen.cso.uiuc.edu>
- References: <4i9sho$3mj@masala.cc.uh.edu>
- Reply-To: n-dade@uiuc.edu
- NNTP-Posting-Host: homer.apr.uiuc.edu
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <4i9sho$3mj@masala.cc.uh.edu>, pmn12564@Bayou.UH.EDU (pat neff) writes:
- > I have a class in which one of the methods is an interrupt. Since I need
- >to hook the interrupt into the interrupt table, I need a pointer to it.
- >Something like:
- >
- >class myobject {
- > void interrupt myinterrupt(...);
- > void dohook ();
- >}
- >
- >void interrupt myobject::myinterrupt (...)
- >{
- > // actual interrupt code here
- >}
- >
- >void myobject::dohook ()
- >{
- > setvect (0x??, this->myinterrupt);
- >}
- >
- > This compiler complains about the line with SETVECT saying I need to
- >call or take the address of the interrupt function. I am trying to take the
- >address of course. I have tried everything, but NO LUCK! Can anyone out
- >there help me?
-
- myinterrupt() is a member function of class myobject---you cannot call
- it with specifying which instance of myobject you are calling it with (in
- other words you have to define in some way what "this" will point to).
-
- You have two possibilities:
- 1) make myinterrupt() a static member function of myobject. Then you
- can call it without needing to specify an instance of myobject. The down
- side is that you can't access any non-static variables of class myobject
- (obviously).
- or
- 2) If you must access a non-static member variable in a specific myobject
- then make the myinterrupt a static member function, and make the pointer
- to that specific myobject a static member as well. Then you can access
- that myobject through the static pointer to it.
-
- ie
-
- class myobject {
- int i;
- static myobject* interruptobject;
- static void myinterrupt();
- void dohook();
- };
-
- myobject::interruptobject = new myobject;
-
- void myobject::myinterrupt() {
- cout << interruptobject->i; // or whatever you want
- }
-
- void myobject::dohook() {
- setvec(0x??, myinterrupt);
- }
-
- If this doesn't make sense then look in your favorite C++ reference
- under "member pointers" (".*" and ".->")
-
- -Nicolas Dade / n9rzb / nicolas-dade@uiuc.edu
-
-
-